const _ = require("lodash");

function getSum(a, b, c) {
  return a + b + c;
}

// let curriedGetSum = _.curry(getSum);
// console.log(curriedGetSum(1, 2, 3));
// console.log(curriedGetSum(1, 2)(3));
// console.log(curriedGetSum(1)(2)(3));

function curry(func) {
  return function curriedFn(...args) {
    // 函数形参可以通过 函数名.length获取, args为函数调用实参
    if (args.length < func.length) {
      return function () {
        return curriedFn(...args.concat(Array.from(arguments)));
      };
    }
    return func(...args);
  };
}

let curriedGetSum = curry(getSum);
console.log(curriedGetSum(1, 2, 3));
console.log(curriedGetSum(1, 2)(3));
console.log(curriedGetSum(1)(2)(3));
